<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">

            <h:form id="cepForm" enctype="multipart/form-data">
                <h1 class="title">
                    <a href="#" class="back" onclick="history.go(-1)"/>
                    Procedimento
                </h1>
                <div class="row">
                    <div class="twelve columns">
                        <p:messages autoUpdate="true"/>
                        <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">Dados Gerais</h4></legend>
                            <p:panel id="customerPrimary" style="background: none; border: none;" 
                                     styleClass="container_24 clearfix ">

                                <p:outputLabel for="active" value="Ativo:" styleClass="grid_3"/>
                                <p:selectBooleanCheckbox id="active" value="#{managerSearchProcedure.editProcedure.active}" />
                                <div class="clear"/>
                                <p:outputLabel for="cod" value="Código:" styleClass="grid_3"/>
                                <p:inputText id="cod" required="true" styleClass="grid_3" value="#{managerSearchProcedure.editProcedure.cod}"/>
                                <p:outputLabel for="name" value="Nome:" styleClass="grid_2"/>
                                <p:inputText id="name" required="true" styleClass="grid_14" value="#{managerSearchProcedure.editProcedure.name}"/>
                                <div class="clear"/>
                                <p:outputLabel value="Duração: " styleClass="grid_3"/>
                                <p:inputText styleClass="grid_3" value="#{managerSearchProcedure.editProcedure.duration}"/>
                                <p:outputLabel  value="Tipo:" styleClass="grid_2"/>  
                                <div class="grid_8">

                                    <p:selectOneMenu value="#{managerSearchProcedure.editProcedure.typeProcedure}" 
                                                     style="width: 100%;" >  
                                        <p:ajax update="@this, :cepForm:customerPrimary" process="@this, :cepForm:customerPrimary"/>
                                        <f:selectItem itemLabel="" itemValue="" />
                                        <f:selectItems  value="#{managerSearchProcedure.selectTypeProcedure()}"/>  
                                    </p:selectOneMenu>
                                </div>

                                <p:outputLabel for="appraisal" value="Possui Laudo ?"
                                               style="display: #{managerSearchProcedure.editProcedure.typeProcedure.name eq 
                                                                 'Exame' ? 'block':'none'}" styleClass="grid_3"/>
                                <p:selectBooleanCheckbox id="appraisal" styleClass="grid_2"
                                                         style="display: #{managerSearchProcedure.editProcedure.typeProcedure.name eq 
                                                                 'Exame' ? 'block':'none'}"
                                                         value="#{managerSearchProcedure.editProcedure.appraisal}" />
                                <div class="clear"/>

                                <p:outputLabel  value="Grupo:" styleClass="grid_3"/>  
                                <div class="grid_19" style="width: 79%;">

                                    <p:selectOneMenu value="#{managerSearchProcedure.editProcedure.groupProcedure}" 
                                                     style="width: 100%;" >  
                                        <f:selectItem itemLabel="" itemValue="" />
                                        <f:selectItems  value="#{managerSearchProcedure.selectGroupProcedure()}"/>  
                                    </p:selectOneMenu>
                                </div>
                                
                                <div class="clear"/>
                                <p:outputLabel for="recomendacao" value="Recomendação:" styleClass="grid_3"/>
                                <p:editor id="recomendacao"  styleClass="grid_19" 
                                                 value="#{managerSearchProcedure.editProcedure.recomendacao}"/>

                            </p:panel>
                        </fieldset>
                        <fieldset>
                            <legend> <h4 style="margin:0 0 10px 0">Valores</h4></legend>
                            <p:panel id="procedureValue" style="background: none; border: none;" 
                                     styleClass="container_24 clearfix ">

                                <p:outputLabel for="operator" value="Convênio" styleClass="grid_3"/>  
                                <p:autoComplete value="#{managerSearchProcedure.operator}" 
                                                id="operator" completeMethod="#{managerOperator.autocomplete}"  
                                                var="o" itemLabel="#{o.name}" itemValue="#{o}" 
                                                styleClass="grid_8" style="width: 28.6%;"  dropdown="true"
                                                converter="#{autocompleteconverter}" />

                                <div class="clear"/>
                                <p:outputLabel value="Valor: " styleClass="grid_3"/>
                                <p:inputText styleClass="grid_8" value="#{managerSearchProcedure.valueProcedure.amount}"
                                             onkeypress="jQuery(this).autoNumeric({aSign: 'R$ ', aSep: '.', aDec: ','} );">
                                    <f:convertNumber type="currency"  locale="pt,BR"  />
                                </p:inputText>

                                <div class="clear"/>
                                <div class="buttonAction">
                                    <p:commandButton value="Adicionar" icon="ui-icon-disk"
                                                     actionListener="#{managerSearchProcedure.addValueProcedure()}"
                                                     process="@this, procedureValue" update="@this, procedureValue"
                                                     styleClass="ui-priority-primary" />
                                </div>
                                <p:dataTable id="valueDataTable" var="value" rowIndexVar="ddt" 
                                             emptyMessage="Nenhum valor cadastrado"
                                             value="#{managerSearchProcedure.valueProcedures}">  

                                    <f:facet name="header">  
                                        Valores por Convênio
                                    </f:facet>  

                                    <p:column headerText="Ação" width="75">
                                        <p:commandButton icon="ui-icon-trash" 
                                                         title="Excluir" alt="Excluir"
                                                         actionListener="#{managerSearchProcedure.removeValue(ddt)}" 
                                                         process="@this, :cepForm:valueDataTable" update="@this, :cepForm:valueDataTable"
                                                         style="width: 25px; position: relative"/>

                                        <p:commandButton icon="ui-icon-pencil" 
                                                         title="Editar" alt="Editar"
                                                         actionListener="#{managerSearchProcedure.editValue(ddt)}" 
                                                         process="@this, :cepForm:valueDataTable" 
                                                         update="@this, :cepForm:valueDataTable, :cepForm:procedureValue"
                                                         style="width: 25px; position: relative"/>
                                    </p:column>
                                    
                                    <p:column headerText="Convênio">  
                                        <h:outputText value="#{value.operator.name}" />
                                    </p:column>  

                                    <p:column headerText="Valor">  
                                        <h:outputLabel value="#{value.amount}" >
                                            <f:convertNumber type="currency" />
                                        </h:outputLabel>
                                    </p:column>  

                                    
                                </p:dataTable> 
                            </p:panel>
                        </fieldset>

                        <div class="buttonAction">
                            <p:commandButton value="Atualizar" icon="ui-icon-disk"
                                             actionListener="#{managerSearchProcedure.update()}"
                                             process="@form" update="@form"
                                             styleClass="ui-priority-primary" />
                            <p:button href="searchprocedure.xhtml" value="Cancelar"  icon="ui-icon-trash" />
                        </div >
                    </div>
                </div>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
